/*********************************************************************************
  *FileName:  lin21.h
  *Version:   V1.0
  *Date:      2024-03-13
**********************************************************************************/

#ifndef  __lin21_H__
#define  __lin21_H__

/***************************************Includes***********************************/
#include "lin_api.h"
#include "lin_cfg.h"
#include "lin_signals.h"
#include "lin_eeprom.h"

/***************************************Macros***********************************/

#define SL_HAS_SAVE_CONFIGURATION_SERVICE	(1U)
#define SL_HAS_BOOTLOADER_SERVICE			(1U)

#define	DEFAULT_LINS_FID_SIZE				(2U)

#define INIT_LINS_NAD_ADDR          (0x0DU)
#define LIN_NAD_FUNCTION            (0x7EU)
#define LIN_NAD_WILDCARD            (0x7FU)
#define LIN_SUPPLIER_ID_WILDCARD    (0x7FFFU)
#define LIN_FUNCTION_ID_WILDCARD    (0xFFFFU)

#define LINS_SUPPLIER_ID            (0x0123U)
#define LINS_FUNCTION_ID            (0x0123U)
#define LINS_VARIANT                (0x01U)
#define LINS_SERIAL_NO              (0x01234567U)
#define LINS_FW_VERSION             (0x0123U)
#define LINS_HW_VERSION             (0x0001U)

#define LIN_FRAME_ID_FUNCTIONAL     (0x7EU)
#define LIN_FRAME_ID_UNASSIGN       (0x00U)
#define LIN_FRAME_ID_DONOTCARE      (0xFFU)


#define LIN_SID_USER_CUSTOM			(0xDBU)

#define LIN_SID_APP_DIAG_BOOT_MODE          (0x20U)
#define BOOT_MODE_HANDSHAKE                 (0x00U)
#define BOOT_MODE_MAGIC_KEY_HANDSHAKE       (0x5A5A55AAU)


#define PRAGMA(x)                           _Pragma(#x)
#define BEGIN_PACK PRAGMA                   (pack(push, 1))
#define END_PACK PRAGMA                     (pack(pop))


/* 进入bootloader模式命令，需要与bootloader程序保持一致 */
#define LIN_SID_APP_DIAG_BOOT_MODE			(0x20U)
#define BOOT_MODE_HANDSHAKE					(0x00U)
#define BOOT_MODE_MAGIC_KEY_HANDSHAKE		(0x5A5A55AAU)



BEGIN_PACK
typedef struct{
    uint8_t command;
    uint32_t magicKey;
}EnterBootloaderFrame_t;

typedef struct{
    uint16_t head;
    uint8_t cmd[3];
}UserCustomFrame_t;
END_PACK

/***************************************Variables***********************************/


extern LIN_Device_Frame_t UnconditionalCmdsTable[2];
extern l_u8 l_ConfiguredNAD;
extern uint8_t g_SlaveSlientSleep;
extern uint8_t g_SlaveCommandSleep;

extern uint16_t g_u16EndSTopMin;
extern uint16_t g_u16EndSTopMax;
/***************************************Functions***********************************/
void ls_ErrorDetected(l_LinError Error);
void lin_hander(void);
void ld_set_configuration(const l_u8* const data, uint8_t length);
void ld_load_configuration(l_u8* data, uint8_t length);
void lin21_Init(void);
void lin21_GotoSleep(void);
#endif
/* [] END OF lin21.h */
